//
//  LikeBeautyView.m
//  ProfilePicture
//
//  Created by 张云江 on 2019/10/16.
//  Copyright © 2019年 张云江. All rights reserved.
//

#import "LikeBeautyView.h"

@interface LikeBeautyView ()
{
    NSMutableArray *arr_M;
}
@end

@implementation LikeBeautyView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        arr_M = [NSMutableArray array];
        
        self.userInteractionEnabled = YES;
        
        [self creatUI];
    }
    return self;
}

- (void)creatUI
{
    UILabel *name = [[UILabel alloc]init];
    name.text = [NSString stringWithFormat:@"人像美颜"];
    name.textColor = kUIColorFromRGA(0x000000, 1);
    name.font = [UIFont systemFontOfSize:kRatio(14)];
    [self addSubview:name];
    [name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(kRatio(20));
        make.top.equalTo(self);
    }];
    
    UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(kRatio(24), kRatio(64), kScreenWidth - kRatio(48), kRatio(24))];
    [self addSubview:slider];
    slider.minimumValue = 0;
    slider.maximumValue = 5;
    slider.value = 2;
    slider.continuous = YES;
    slider.layer.cornerRadius = 5;
    slider.layer.masksToBounds = YES;
    
    slider.minimumTrackTintColor = kUIColorFromRGB(0x2F54EB);
    slider.maximumTrackTintColor = kUIColorFromRGB(0x979797);
    
    [slider setMinimumTrackImage:[UIImage imageNamed:@"props_box_progress_hight"] forState:UIControlStateNormal];
    [slider setMaximumTrackImage:[UIImage imageNamed:@"props_box_progress"] forState:UIControlStateNormal];
    [slider setThumbImage:[UIImage imageNamed:@"props_box_slider"] forState:UIControlStateNormal];
    
    [slider addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged];
    
    self.value = 2;
    
    UILabel *lab = [[UILabel alloc]init];
    lab.text = @"0级";
    lab.textColor = kUIColorFromRGA(0x000000, 0.65);
    lab.font = [UIFont systemFontOfSize:kRatio(16)];
    [self addSubview:lab];
    [lab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(slider.mas_bottom).offset(kRatio(18));
        make.left.equalTo(slider.mas_left);
    }];
    
    lab1 = [[UILabel alloc]init];
    lab1.text = @"2级";
    lab1.textColor = kUIColorFromRGA(0x2F54EB, 1);
    lab1.font = [UIFont systemFontOfSize:kRatio(16)];
    [self addSubview:lab1];
    [lab1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(slider.mas_bottom).offset(kRatio(18));
        make.right.equalTo(slider.mas_right);
    }];
    
    CustomBtn *cusBtn = [[CustomBtn alloc]init];
    cusBtn.hidden = YES;
    cusBtn.tag = 100;
    [cusBtn setCustomBtnwtihNormal:@"mf_likeBeauty_1" withSelected:@"" withLabel:@"无美颜"];
    [cusBtn addTarget:self action:@selector(onCusAkeyisBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    cusBtn.backgroundColor = kUIColorFromRGA(0xF3F5FF, 1);
    [self addSubview:cusBtn];
    [cusBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(kRatio(20));
        make.top.equalTo(slider.mas_bottom).offset(kRatio(23));
        make.width.mas_equalTo(kRatio(52));
        make.height.mas_equalTo(kRatio(64));
    }];
    
    UIButton *akeyisBtn = [[UIButton alloc]init];
    akeyisBtn.backgroundColor = kUIColorFromRGA(0xF3F5FF, 1);
    akeyisBtn.layer.cornerRadius = 5;
    akeyisBtn.layer.masksToBounds = YES;
    akeyisBtn.titleLabel.font = [UIFont systemFontOfSize:kRatio(14)];
    akeyisBtn.layer.borderWidth = .5;
    akeyisBtn.layer.borderColor = kUIColorFromRGA(0x2F54EB, 1).CGColor;
    
    [akeyisBtn setTitle:@"一键美颜" forState:UIControlStateNormal];
    [akeyisBtn setTitleColor:kUIColorFromRGA(0x2F54EB, 1) forState:UIControlStateNormal];
    [akeyisBtn addTarget:self action:@selector(onAkeyisBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:akeyisBtn];
    [akeyisBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top);
        make.right.equalTo(self.mas_right).offset(kRatio(-20));
        make.height.mas_equalTo(kRatio(30));
        make.width.mas_equalTo(kRatio(100));
    }];
    
    UIScrollView *likeBeautyScroll = [[UIScrollView alloc]initWithFrame:CGRectMake(kRatio(72), kRatio(71), kScreenWidth - kRatio(72) - kRatio(20), kRatio(64))];
    likeBeautyScroll.hidden = YES;
    likeBeautyScroll.userInteractionEnabled = YES;
    likeBeautyScroll.showsHorizontalScrollIndicator = NO;
    [self addSubview:likeBeautyScroll];
    
    NSArray *titleArr = @[@"瘦脸",@"美白",@"磨皮",@"眼睛",@"嘴巴",@"光效"];
    NSArray *titleArr1 = @[@"mf_likeBeauty_01",@"mf_likeBeauty_02",@"mf_likeBeauty_03",@"mf_likeBeauty_04",@"mf_likeBeauty_05",@"mf_likeBeauty_06"];
    NSArray *titleArr2 = @[@"mf_likeBeauty_select_01",@"mf_likeBeauty_select_02",@"mf_likeBeauty_select_03",@"mf_likeBeauty_select_04",@"mf_likeBeauty_select_05",@"mf_likeBeauty_select_06"];
    
    for (int i = 0; i < 6; i++) {
        
        CustomBtn *cuBtn = [[CustomBtn alloc]init];
        [cuBtn setCustomBtnwtihNormal:titleArr1[i] withSelected:titleArr2[i] withLabel:titleArr[i]];
        [cuBtn addTarget:self action:@selector(onToBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        
        [likeBeautyScroll addSubview:cuBtn];
        [cuBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(likeBeautyScroll.mas_left).offset(kRatio(15 + (52 + 15) * i));
            make.top.equalTo(likeBeautyScroll.mas_top);
            make.width.mas_equalTo(kRatio(52));
            make.height.mas_equalTo(kRatio(64));
        }];
        [arr_M addObject:cuBtn];
        
    }
    
    likeBeautyScroll.contentSize = CGSizeMake(kRatio((52 + 15) * 6 + 20), 0);
}

- (void)onToBtnClick:(CustomBtn *)btn
{
    for (CustomBtn *cbtn in arr_M) {
        [cbtn setCustomSelected:NO];
    }
    [btn setCustomSelected:YES];
}

- (void)sliderValueChanged:(UISlider *)slider
{
    self.value = (int)slider.value;
    switch (self.value) {
        case 0:
        {
            lab1.text = @"0级";
        }
            break;
        case 1:
        {
            lab1.text = @"1级";
        }
            break;
        case 2:
        {
            lab1.text = @"2级";
        }
            break;
        case 3:
        {
            lab1.text = @"3级";
        }
            break;
        case 4:
        {
            lab1.text = @"4级";
        }
            break;
        case 5:
        {
            lab1.text = @"5级";
        }
            break;
            
        default:
            break;
    }
}

- (void)onCusAkeyisBtnClick:(UIButton *)btn
{
    WCDelegate.currFairLevel = 0;
    self.LikeBeautyClick(0);
}

- (void)onAkeyisBtnClick:(UIButton *)btn
{
    WCDelegate.currFairLevel = self.value;
    self.LikeBeautyClick(self.value);
}
@end
